<template>
	<view class="content">

		<div class="order-title back">
			<view class="title">
				累计佣金：+ {{total}} 元
			</view>
			<view class="order_container_top border_bottom display align-items space-between back">
				<view class="order_container_top_name " :class="{act : current==0}" @click="onClickItem1(0)">全部</view>
				<view class="order_container_top_name " :class="{act : current==1}" @click="onClickItem1(1)">待付款</view>
				<view class="order_container_top_name " :class="{act : current==2}" @click="onClickItem1(2)">待发货</view>
				<view class="order_container_top_name " :class="{act : current==3}" @click="onClickItem1(3)">待收货</view>
				<view class="order_container_top_name " :class="{act : current==4}" @click="onClickItem1(4)">已完成</view>
			</view>
		</div>

		<view>
			<view class="form_list">
				<view class="list" v-for="(item,index) in orderList" :key="index">
					<view class="list_w">
						<view class="tit">
							<view class="left">
								买家:{{item.nickname}}
							</view>
							<!-- <view class="cen">
								订单编号：
							</view> -->
							<view class="right" v-if="item.status==1">待付款</view>
							<view class="right" v-if="item.status==2">待发货</view>
							<view class="right" v-if="item.status==3">待收货</view>
							<view class="right" v-if="item.status==4">已完成</view>
						</view>
						<view class="con" v-for="(i,idx) in item.goods" :key="idx" @click="goOrderDetails(item.id)" :style="i===item.goods.length-1?'margin-bottom:20rpx;':''">
							<image :src="imgUrl+i.goods_image" mode=""></image>
							<view class="left">
								<view class="name ellipsis_more ellipsis_more_2">{{i.goods_name}}</view>
								<view class="num">
									×{{i.goods_num}}
								</view>
								<view class="mony">
									¥{{i.goods_price}}
								</view>
							</view>
						</view>
						<view class="heji">
							共{{item.goods_num}}件商品 合计：<text>¥{{item.order_amount}}</text>
						</view>
					</view>
				</view>

			</view>
		</view>
		<view class="no_thing" v-if="noOrder">
			<image src="../../../static/icon/no_order.png"></image>
			<view class="no_thing_text">暂无内容</view>
		</view>
		<view class="over" v-if="flag">我也是有底线的</view>
		<is-login v-on:childClick='listenToClose' v-on:childClickAgain='listenToCloseAgain' v-if="isLogin==0"></is-login>
	</view>
</template>

<script>
	import isLogin from '../../../components/isLogin.vue'
	import {
		uniSegmentedControl
	} from '@dcloudio/uni-ui'
	export default {
		components: {
			uniSegmentedControl,
			isLogin
		},
		data() {
			return {
				current: 0,
				orderList: [],
				page: 1,
				limit: 10,
				flag: true,
				imgUrl: '',
				noOrder: false,
				isLogin: 1,
				total: 0
			}
		},
		onLoad(optain) {
			let that = this
			this.imgUrl = that.$imgUrl
			if (!uni.getStorageSync('openid')) {
				this.isLogin = 0
			} else {
				this.getOrderList()
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.orderList = []
			this.flag = false
			this.noOrder = false
			setTimeout(() => {
				this.getOrderList(() => {
					uni.stopPullDownRefresh()
				})
			}, 1000)
		},
		onReachBottom() {
			if (this.orderList.length < this.page * this.limit) {
				return this.flag = true
			}
			this.noOrder = false
			this.page++
			this.getOrderList()
		},
		methods: {
			// 分类
			onClickItem1(e) {
				this.current = e
				this.page = 1
				this.orderList = []
				this.flag = false
				this.noOrder = false
				this.getOrderList()
			},
			// 获取订单列表
			getOrderList(callback) {
				let that = this
				var data = {
					openid: uni.getStorageSync('openid'),
					status: that.current,
					page: that.page,
					limit: that.limit
				}
				this.$myRequest.post(this.$api.distribution.getTeamOrderInfoPage, data).then(res => {
					if (res.code == '200') {
						callback && callback()
						if (that.page == 1) {
							if (res.data.data.length == 0) {
								this.noOrder = true
								this.flag = false
								return  false;
							}
							console.log( res.data.total)
							this.total = res.data.total
							this.orderList = res.data.data
						} else {
							this.orderList = [...this.orderList, ...res.data.data]
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			onClickItem(even) {
				this.current = even.currentIndex
			},
			goOrderDetails(id) {
				uni.navigateTo({
					url: "../orderDetails/orderDetails?id="+id
				})
			},
			// 监听
			listenToClose(msg) {
				this.isLogin = msg
			},
			listenToCloseAgain() {
				this.getOrderList()
			},
		}
	}
</script>

<style scoped lang="scss">
	.act {
		border-bottom: 2rpx solid #294D7C !important;
	}

	.content {
		width: 690rpx;
		margin: 0 auto;

		.order-title {
			position: -webkit-sticky;
			position: sticky;
			top: 0;
			left: 0;
			right: 0;
			margin: auto;
			height: 175rpx;

			.title {
				width: 689rpx;
				line-height: 90rpx;
				background: #FFFFFF;
				box-shadow: 0px 2rpx 10rpx 0px rgba(90, 96, 105, 0.14);
				border-radius: 10rpx;
				text-indent: 20rpx;
				font-size: 26rpx;
				color: #333333;
				margin: 20rpx 0;
			}

			.order_container_top {
				height: 65rpx;
				width: 690rpx;

				.order_container_top_name {
					padding: 0 8rpx;
					height: 60rpx;
					line-height: 60rpx;
				}

			}
		}


		.form_list {
			margin-top: 30rpx;

			.list {
				width: 690rpx;
				border: 1px solid #E3E3EF;
				border-radius: 10rpx;
				margin-bottom: 30rpx;

				.list_w {
					width: 650rpx;
					margin: 0 auto;

					.tit {
						width: 100%;
						height: 66rpx;
						line-height: 66rpx;
						border-bottom: 1rpx solid #E3E3EF;
						margin-bottom: 20rpx;

						.left {
							font-size: 22rpx;
							color: #333333;
							float: left;
						}

						.cen {
							font-size: 20rpx;
							color: #666666;
							float: left;
						}

						.right {
							color: #F21515;
							font-size: 26rpx;
							float: right;
						}
					}

					.con {
						display: flex;
						align-items: center;
						height: 140rpx;
						// margin-bottom: 25rpx;

						image {
							width: 140rpx;
							height: 140rpx;
							margin-right: 36rpx;
							margin-left: 5rpx;
						}

						.left {
							width: 450rpx;

							.name {
								color: #333333;
								font-size: 26rpx;
								height:70rpx;
							}

							.num {
								text-align: right;
								font-size: 22rpx;
								color: #666666;
							}

							.mony {
								font-size: 24rpx;
								color: #333333;
								text-align: right;
							}
						}
					}

					.heji {
						font-size: 28rpx;
						color: #333333;
						text-align: right;
						font-weight: bold;
						margin-bottom: 20rpx;

						text {
							color: #F21515;
						}
					}

				}
			}
		}
	}
</style>
